﻿using SimpleUnitity.Database.Config;
using SimpleUnitity.Log;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SimpleUnitity.Database.Extension
{
    public static class DbProviderSectionExtensions
    {
        public static DataHelper CreateDataHelper(this DbProviderSection section, string connectionString, ILog log)
        {
            var conn = section.GetConnection();
            conn.ConnectionString = connectionString;
            var adapter = section.GetDataAdapter();
            var tools = new ProviderDbTool(conn, adapter, section.ParameterPrefix, section.StatementPrefix, section.StatementSuffix)
            {
                IdentitySQL = section.IdentitySQL,
                StatementSymbolAlias = section.StatementSymbolAlias
            };
            return new DataHelper(tools, log) { IdentitySQL = tools.IdentitySQL };
        }
    }
}
